package cn.qhuan.modules.controller;

import cn.qhuan.modules.dtos.*;
import cn.qhuan.modules.entity.Works;
import cn.qhuan.modules.service.IWorksService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.UUID;

/**
* @Description: 作品表
* @Author: 司翔宇
* @Date:   2020-12-18
* @Version: V1.0
*/
@Api(tags="作品表")
@RestController
@RequestMapping("/works")
@Slf4j
public class WorksController extends JeecgController<Works, IWorksService> {
   @Autowired
   private IWorksService worksService;


    /**
     * 条件分页查询
     * @param dto
     * @return
     */
    @AutoLog(value = "作品表-条件分页查询")
    @ApiOperation(value="作品表-条件分页查询", notes="作品表-条件分页查询")
    @PostMapping(value = "/list")
    public Result<?> findList(@RequestBody WorksDto dto) {
       return worksService.findList(dto);
    }

    /**
    *   添加
    *
    * @param dto
    * @return
    */
   @AutoLog(value = "作品表-添加")
   @ApiOperation(value="作品表-添加", notes="作品表-添加")
   @PostMapping(value = "/add")
   public Result<?> add(@RequestBody WorksDtoVo dto) {

       return worksService.saveWorks(dto);
   }

   /**
    *  编辑
    *
    * @param dto
    * @return
    */
   @AutoLog(value = "作品表-编辑")
   @ApiOperation(value="作品表-编辑", notes="作品表-编辑")
   @PutMapping(value = "/edit")
   public Result<?> edit(@RequestBody WorksDtoVo dto) {

       return worksService.editWorks(dto);
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "作品表-通过id删除")
   @ApiOperation(value="作品表-通过id删除", notes="作品表-通过id删除")
   @DeleteMapping(value = "/delete")
   public Result<?> delete(@RequestParam(name="id",required=true) String id) {
       worksService.removeById(id);
       return Result.OK("删除成功!");
   }

   /**
    *  批量删除
    *
    * @param ids
    * @return
    */
   @AutoLog(value = "作品表-批量删除")
   @ApiOperation(value="作品表-批量删除", notes="作品表-批量删除")
   @DeleteMapping(value = "/deleteBatch")
   public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.worksService.removeByIds(Arrays.asList(ids.split(",")));
       return Result.OK("批量删除成功!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @AutoLog(value = "作品表-通过id查询")
   @ApiOperation(value="作品表-通过id查询", notes="作品表-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<?> queryById(@RequestParam(name="id",required=true) String id) {

       return worksService.findWorksVo(Integer.valueOf(id));
   }

   /**
   * 导出excel
   *
   * @param request
   * @param qhWorks
   */
   @RequestMapping(value = "/exportXls")
   public ModelAndView exportXls(HttpServletRequest request, Works qhWorks) {
       return super.exportXls(request, qhWorks, Works.class, "作品表");
   }

   /**
     * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
   @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
   public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
       return super.importExcel(request, response, Works.class);
   }
    /**
     * 审核操作
     * @param worksAuthDto
     * @return
     */
    @AutoLog(value = "作品表-审核操作")
    @ApiOperation(value = "作品表-审核操作", notes = "作品表-审核操作")
    @PostMapping("/auth")
    public Result authPass(@RequestBody WorksAuthDto worksAuthDto,Integer type){
        return worksService.updateStatus(worksAuthDto,type);
    }



    /**
     * 前台是否显示
     * @param worksShowDto
     * @return
     */
    @AutoLog(value = "作品表-前台是否显示")
    @ApiOperation(value = "作品表-前台是否显示", notes = "作品表-前台是否显示")
    @PostMapping("/show")
    public Result hideWorks(@RequestBody WorksShowDto worksShowDto,Integer type){
        return worksService.updateShowStatus(worksShowDto,type);
    }

    /**
     * 加载最新数据
     * @param dto
     * @return
     */
    @AutoLog(value = "作品表-加载最新上传数据")
    @ApiOperation(value="作品表-加载最新上传数据", notes="作品表-加载最新上传数据")
    @PostMapping(value = "/loadNewList")
    public Result<?> loadNewWorks(@RequestBody WorksTimeDto dto){
        return worksService.loadNewWorks(dto);
    }

    /**
     * 作品设置所属展厅
     * @param worksId
     * @param exhiId
     * @return
     */
    @AutoLog(value = "作品表-作品设置展厅")
    @ApiOperation(value="作品表-作品设置展厅", notes="作品表-作品设置展厅")
    @GetMapping(value = "/addWorksToExhi")
    public Result<?> addWorksToExhi(@RequestParam String worksId, String exhiId){

        return worksService.addWorksToExhi(String.valueOf(UUID.randomUUID()),worksId,exhiId);
    }

}
